home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.525 < prev    next >
Text File  |  1992-02-06  |  2KB  |  61 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f3\fmodern Courier;\f0\fswiss Helvetica;}
  2. \paperw11440
  3. \paperh9000
  4. \margl120
  5. \margr120
  6. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b0\i0\ul0\fs28 \
  7. Q:  How can I remove a menu cell from a menu?  I can disable, enable, add, sizeToFit, update, and free, but I cannot get the actual cell to disappear from the submenu.  \
  8. \
  9. A:  You need to remove the cell from the matrix maintained by the menu, and then have the menu resize to fit its new cells.    Here is a code snippet:\
  10. \
  11.  
  12. \f3\fs24 - removeMenuCell:(int)cellNum from:theMenu\
  13. \{\
  14.     id matrix;\
  15. \
  16.     [theMenu disableFlushWindow];  \
  17.     matrix = [theMenu itemList];\
  18.     [matrix removeRowAt:cellNum andFree:YES];    // remove cell\
  19.     [theMenu sizeToFit];      // adjust menu to new size \
  20.     [[theMenu reenableFlushWindow] flushWindow];\
  21.     return self;\
  22. \}\
  23. \
  24.  
  25. \f2\fs28 You can disable window flushing before removing the cell to avoid screen flicker, but be sure to reenable it once you're done.  The above method is used if you know the number of the cell you want to remove.  If you only have the menu cell's title, you can do this:\
  26.  
  27. \f3\fs24 \
  28. - removeMenuCellName:(const char*)cellTitle from:theMenu\
  29. \{\
  30.     int     i, count;\
  31.     id   matrix, cells;\
  32.     id      cell;\
  33.     const char*     title;\
  34. \
  35.     [theMenu disableFlushWindow];\
  36.     matrix = [theMenu itemList];\
  37.     cells = [matrix itemList];   // get the List of cells\
  38.     count = [cells count];\
  39.     for(i = 0; i < count; i++) \
  40.     \{            \
  41.         cell = [cells objectAt:i];\
  42.      title = [cell title];\
  43.      if(s && !strcmp(s, cellTitle) \
  44.      \{ // compare to find correct title\
  45.             [matrix removeRowAt:i andFree:YES];\
  46.             break;\
  47.         \}\
  48.     \}\
  49.     [theMenu sizeToFit];  // resize menu\
  50.     [[theMenu reenableFlushWindow] flushWindow];\
  51.     return self;\
  52. \}\
  53. \
  54.  
  55. \f2\fs28 QA525\
  56. \
  57. Valid for 1.0\
  58. Valid for 2.0\
  59. \
  60.  
  61.